package com.zjr.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ModelDriven;
import com.zjr.domain.Log;
import com.zjr.service.LogService;
import com.zjr.utils.*;
/**
 * 日志action类
 * */
public class LogAction extends SuperAction implements ModelDriven<Log>{
	private static final long serialVersionUID = 1L;
	
	private Log log = new Log();
	@Override
	public Log getModel() {
		return log;
	}
	
	private LogService logService;
	public void setLogService(LogService logService) {
		this.logService = logService;
	}
	
	//添加日志
	public String save(){
		if(logService.save(log)){
			return "add_success";
		}else{
			return "add_failure";
		}
	}
	
	public String list(){
			
		List<Log> logs = logService.find((ViewUser) session.getAttribute("existUser"));
		if(logs != null){
			request.setAttribute("logs", logs);
			return "list";
		}else{
			return "no_log";
		}
	}
	
	public String findById(){
		int lid = Integer.parseInt(request.getParameter("lid"));
		Log log = logService.findById(lid);
		request.setAttribute("modify_log", log);
		return "find";
	}
	
	public String modify(){
		logService.modify(log);
		return "modify";
	}
	
	public String delete(){
		int lid = Integer.parseInt(request.getParameter("lid"));
		logService.delete(lid);
		return "delete";
	}
}
